package com.drakulo.games.ais.ui;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

public final class ImageManager {
	private static final String DATA_PATH = File.separator + "data" + File.separator;
	private static final String GFX_PATH = DATA_PATH + "gfx" + File.separator;

	private static final String EXT = ".png";
	private static Map<String, Image> cache = new HashMap<String, Image>();

	/**
	 * Private constructor to force static use
	 */
	private ImageManager() {
		// Nothing there
	}

	public static Image getGfx(String ref) throws SlickException {
		String path = GFX_PATH + ref + EXT;
		if (!cache.containsKey(path)) {
			System.out.println("Getting resource : " + path);
			Image img = new Image(path);
			cache.put(path, img);
		}
		return cache.get(path);
	}
}
